package com.cheer.vo;

import cn.hutool.core.io.FileUtil;
import com.cheer.entity.StandingBookDocument;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;

import java.io.File;

/**
 * @author cheer
 */
@Data
@Accessors(chain = true)
public class DocumentVO {

    private String url;

    private String name;

    private String link;


    public static DocumentVO build(StandingBookDocument document, String resourceUrl) {
        DocumentVO documentVO = new DocumentVO();
        documentVO.setUrl(document.getDocUrl());
        documentVO.setName(StringUtils.substringAfterLast(document.getDocUrl(), File.separator));
        documentVO.setLink(resourceUrl + document.getDocUrl());
        return documentVO;
    }

    public static DocumentVO build(String fileName, String fileUrl, String resourceUrl) {
        DocumentVO documentVO = new DocumentVO();
        documentVO.setUrl(fileUrl);
        documentVO.setName(fileName);
        documentVO.setLink(resourceUrl + fileUrl);
        return documentVO;
    }

    public static DocumentVO build(String fileUrl, String resourceUrl) {
        DocumentVO documentVO = new DocumentVO();
        documentVO.setUrl(fileUrl);
        documentVO.setName(FileUtil.getName(fileUrl));
        documentVO.setLink(resourceUrl + fileUrl);
        return documentVO;
    }
}
